package cool.mor.controller;

import cool.mor.dto.DepartmentEditorDto;
import cool.mor.dto.PersonnelManagementPageQueryDto;
import cool.mor.dto.PersonnelManagementSalaryQueryDto;
import cool.mor.dto.RewardAndPunishmentRecordDto;
import cool.mor.entity.Employee;
import cool.mor.form.DepartmentEditorForm;
import cool.mor.form.EmployeeForm;
import cool.mor.form.PersonnelManagementPageQueryForm;
import cool.mor.form.RewardAndPunishmentRecordForm;
import cool.mor.service.PersonnelManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Ivan
 */
@RestController
public class PersonnelManagementController {
    @Autowired
    PersonnelManagementService personnelManagementService;
    /**
     * 根据前端的分页请求来返回一个分页对象数据
     *            |
     *            |   Mapping注解中的默认值是 （value = ”“）  莫失莫忘，今日尴尬 3.9
     *           \/
     */
    @GetMapping(value = "/getPersonnelManagementDataByPage")
    public PersonnelManagementPageQueryDto getPersonnelManagementDataByPage(PersonnelManagementPageQueryForm personnelManagementPageQueryForm){
        return personnelManagementService.queryPersonnelManagementDataByPage(personnelManagementPageQueryForm);
    }
    /**
     * 前端获取到分页对象后，根据遍历每条员工记录的id来查询其部门基本薪资和奖惩总额
     *          --------暂留一个问题，如何直接在后端处理page对象，无需两次请求
     */
    @GetMapping(value = "/getPersonnelManagementSalaryQuery")
    public PersonnelManagementSalaryQueryDto getPersonnelManagementSalaryQuery(String employeeId){
        return personnelManagementService.queryPersonnelManagementSalary(employeeId);
    }
    /**
     * 前端提交部门与岗位调整的表单数据到后端（员工id，入职日期时间戳，部门号，岗位名称）
     *      根据表单数据更新用户信息
     */
    @PutMapping(value = "/putDepartmentEditor")
    public DepartmentEditorDto putDepartmentEditor(EmployeeForm employeeForm){
        return personnelManagementService.updateDepartmentEditor(employeeForm);
    }
    /**
     * 前端提交奖惩记录到后端（员工id，奖惩类型，奖惩日期时间戳，奖惩原因，奖惩金额    --附件功能暂留）
     */
    @PostMapping(value = "/postRewardAndPunishmentRecordForm")
    public RewardAndPunishmentRecordDto postRewardAndPunishmentRecordForm(RewardAndPunishmentRecordForm rewardAndPunishmentRecordForm){
        return personnelManagementService.addRewardAndPunishmentRecord(rewardAndPunishmentRecordForm);
    }
}
